<template>
    <div>
        <vue-editor v-model="content" useCustomImageHandler @image-added="handleImageAdded"></vue-editor>
    </div>
</template>

<script>
import { VueEditor } from 'vue2-editor'
import request from '@/utils/request'
export default {
    components: {
        VueEditor
    },
    model:{
        prop:'value',
        event:'modelChange'
    },
    props:{
        value:{
            type:String | Number,
            required:true,
        }
    },
    data() {
        return {
            content: this.value
        }
    },
    watch:{
        
        content(val){
            this.$emit('modelChange',val);
        }
    },
    methods: {
         async handleImageAdded(file, Editor, cursorLocation, resetUploader){

            console.log(file,'上传',Editor);

            var formData = new FormData();

            formData.append("image", file);

            const res = await request.post('upload/admin',formData);

            Editor.insertEmbed(cursorLocation, "image", res);

            resetUploader();
        }
    }
}

</script>